<template>
    <div class="container">
        <!-- header -->
        <div class="header">
            <el-tag type="warning">你的反馈将推送给用户，请认真反馈用户，解释未开通原因，告知开通进度</el-tag>
        </div>
        <!-- /header -->

        <!-- table -->
        <el-table
            :data="tableData"
            height="100%"
            style="width: 100%;"
            border
        >
            <el-table-column
                label="ID"
                width="100px"
                type="index"
                align="center"
            />
            <el-table-column
                prop="true_name"
                label="用户姓名"
                show-overflow-tooltip
                :formatter="emptyFormatter"
            />
            <el-table-column
                prop="phone"
                label="手机号"
                show-overflow-tooltip
                :formatter="emptyFormatter"
            />
            <el-table-column
                prop="school_name"
                label="学校名称"
                show-overflow-tooltip
                :formatter="emptyFormatter"
            />
            <el-table-column
                prop="reply_content"
                label="反馈内容"
                show-overflow-tooltip
                :formatter="emptyFormatter"
            >
                <template slot-scope="scope">
                    <span v-if="scope.row.reply_status == 0">--</span>
                    <span v-if="scope.row.reply_status == 1">{{ scope.row.reply_content }}</span>
                </template>
            </el-table-column>
            <el-table-column
                label="操作"
                fixed="right"
                :width="250"
            >
                <template slot-scope="scope">
                    <span
                        class="curse-feed"
                        @click="fnFeedBook(scope.row)"
                    >反馈</span>
                </template>
            </el-table-column>
        </el-table>
        <!-- /table -->

        <!-- dialog -->
        <el-dialog
            title="反馈"
            width="530px"
            custom-class="schedule-dialog"
            :visible.sync="showFeedDialog"
        >
            <el-form
                :model="ruleForm"
                :rules="rules"
                ref="ruleForm"
            >
                <el-form-item
                    prop='textarea'
                    label="反馈内容"
                >
                    <el-input
                        type="textarea"
                        :autosize="{ minRows: 2, maxRows: 4}"
                        placeholder="请输入内容"
                        v-model="ruleForm.textarea"
                        maxlength="50"
                        show-word-limit
                    />
                </el-form-item>
            </el-form>
            <div
                slot="footer"
                class="dialog-footer"
            >
                <el-button
                    size="small"
                    type="primary"
                    @click="submitForm('ruleForm')">提交</el-button>
            </div>
        </el-dialog>
        <!-- dialog -->

        <!-- 分页 -->
        <div
            class="pagination-wrapper clearfix"
            v-if="tableData.length > 0"
        >
            <el-pagination
                background
                layout="total, prev, pager, next"
                :current-page.sync="page.now_page"
                :total="page.total_count"
                :page-size="page.page_size"
                @current-change="getTableData"
            />
        </div>
        <!-- /分页 -->
    </div>
</template>

<script>
export default {
    data () {
        return {
            school_id: '',
            apply_no: '',
            tableData: [],
            page: {
                now_page: 1,
                total_count: 0,
                page_size: 0
            },
            showFeedDialog: false,
            ruleForm: {
                textarea: ''
            },
            rules: {
                textarea: [
                    { required: true, message: '请填写反馈内容', trigger: 'blur' }
                ]
            }
        };
    },
    created () {
        const arg = this.$route.query;

        if (arg['school_id'] !== undefined) {
            this.school_id = arg['school_id'];
        }

        this.setHeader();
        this.getTableData();
    },
    methods: {
        /**
         * 设置表单header
         */
        setHeader () {
            this.$store.commit('SET_HEADER', [{
                title: "APP后台",
            },
            {
                title: '社交'
            },
            {
                title: "申请用户列表"
            }]
            );
        },
        /**
         * 获取表格数据
         */
        getTableData (page) {
            this.$post('/student/forum_apply%5Cget_list', {
                page_id: page || this.page.now_page,
                school_id: this.school_id,
            }, resp => {
                if (resp.code == 1) {
                    this.tableData = resp.data.list;
                    this.page.now_page = resp.data.page.now_page;
                    this.page.total_count = resp.data.page.total_count;
                    this.page.page_size = resp.data.page.page_size;
                }
            });
        },
        /**
         * 提交反馈内容
         */
        submitForm(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    this.$post('/student/forum_apply%5Creply', {
                        apply_no: this.apply_no,
                        reply_content: this.ruleForm['textarea']
                    }, resp => {
                        if (resp.code == 1) {
                            this.$message({
                                type: 'success',
                                message: '操作成功'
                            });
                            this.showFeedDialog = !this.showFeedDialog;
                            this.getTableData(1);
                        } else if (resp.code == 0) {
                            this.$message({
                                type: 'warning',
                                messaeg: resp.msg
                            });
                        }
                    });
                } else {
                    console.log('error submit!!');
                    return false;
                }
            });
        },
        /**
         * 反馈
         */
        fnFeedBook (row) {
            this.showFeedDialog = !this.showFeedDialog;
            this.apply_no = row.apply_no;
        },
        /**
         * 过滤函数
         */
        emptyFormatter(row, column, val) {
            if (!val) {
                return '--';
            }
            return val;
        }
    }
};
</script>

<style lang="less" scoped>
    .container {
        background-color: #fff;
        padding: 15px;
        display: flex;
        flex-direction: column;
        position: relative;
        .header {
            margin-bottom: 20px;
            position: relative;
            display: flex;
            align-items: center;
            justify-content: space-between;
            .header-right {
                display: flex;
                .el-button {
                    margin-left: 20px;
                }
            }
        }
        .curse-feed {
            color: rgb(64, 158, 255);
            cursor: pointer;
        }
        .pagination-wrapper {
            padding-top: 10px;
            .el-pagination {
                float: right;
                padding: 0;
                background-color: transparent;
            }
        }
        .dialog-footer {
            display: flex;
            justify-content: center;
            align-items: center;
        }
    }
</style>
<style lang="less">
    .el-table__body-wrapper .el-table__body .el-table__row td {
        border-right: none;
    }
    .el-table__header-wrapper .el-table__header .has-gutter tr th {
        border-right: none;
    }
</style>